package jpm.common;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import jpm.common.JPMException.ErrorCode;

import org.junit.Test;

public class UtilsTest {
	@Test public void canParseAsInt() {
		assertEquals(true, Utils.canParseAsInt("1000"));
		assertEquals(true, Utils.canParseAsInt("-1000"));
		assertEquals(false, Utils.canParseAsInt("-a1000"));
	}
	
	@Test public void safeParseAsInt() {
		assertEquals(100, Utils.safeParseAsInt("100"));		
		assertEquals(0, Utils.safeParseAsInt("0"));
		
		try {
			Utils.safeParseAsInt("");
			assertTrue(false);
		} catch (JPMException ex) {
			assertEquals(ErrorCode.ERROR_INVALID_INPUT, ex.getErrorCode());
		}
	}
}
